package cn.iocoder.yudao.module.product.controller.admin.process;

import cn.iocoder.yudao.module.product.controller.admin.process.vo.EmissionProcessCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.process.vo.EmissionProcessRespVO;
import cn.iocoder.yudao.module.product.controller.admin.process.vo.EmissionProcessUpdateReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.module.product.service.process.EmissionProcessService;

@Tag(name =  "管理后台 - 排放源-工序关联")
@RestController
@RequestMapping("/product/emission-process")
@Validated
public class EmissionProcessController {

    @Resource
    private EmissionProcessService emissionProcessService;

    @PostMapping("/create")
    @Operation(summary = "创建排放源-工序关联")
    @PreAuthorize("@ss.hasPermission('product:emission-process:create')")
    public CommonResult<Long> createEmissionProcess(@Valid @RequestBody EmissionProcessCreateReqVO createReqVO) {
        return success(emissionProcessService.createEmissionProcess(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新排放源-工序关联")
    @PreAuthorize("@ss.hasPermission('product:emission-process:update')")
    public CommonResult<Boolean> updateEmissionProcess(@Valid @RequestBody EmissionProcessUpdateReqVO updateReqVO) {
        emissionProcessService.updateEmissionProcess(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除排放源-工序关联")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('product:emission-process:delete')")
    public CommonResult<Boolean> deleteEmissionProcess(@RequestParam("id") Long id) {
        emissionProcessService.deleteEmissionProcess(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得排放源-工序关联")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('product:emission-process:query')")
    public CommonResult<EmissionProcessRespVO> getEmissionProcess(@RequestParam("id") Long id) {
        EmissionProcessRespVO emissionProcessRespVO = emissionProcessService.getEmissionProcess(id);
        return success(emissionProcessRespVO);
    }

}
